package com.demo.config;

import lombok.Data;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@Data
public class SyncConfig {
    private final Properties properties;

    private SyncConfig() {
        properties = new Properties();
        try (InputStream input = SyncConfig.class.getClassLoader().getResourceAsStream("application.properties")) {
            if (input == null) {
                throw new RuntimeException("无法找到 application.properties 文件");
            }
            properties.load(input);
        } catch (IOException e) {
            throw new RuntimeException("加载配置文件失败", e);
        }
    }

    private static class SingletonHolder {
        private static final SyncConfig INSTANCE = new SyncConfig();
    }

    public static SyncConfig getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public String getMySQLHost() {
        return properties.getProperty("mysql.host");
    }

    public int getMySQLPort() {
        return Integer.parseInt(properties.getProperty("mysql.port"));
    }

    public String getMySQLDatabase() {
        return properties.getProperty("mysql.database");
    }

    public String getMySQLTable() {
        return properties.getProperty("mysql.table");
    }

    public String getMySQLUsername() {
        return properties.getProperty("mysql.username");
    }

    public String getMySQLPassword() {
        return properties.getProperty("mysql.password");
    }

    public String getGaussURL() {
        return properties.getProperty("gauss.url");
    }

    public String getGaussTable() {
        return properties.getProperty("gauss.table");
    }

    public String getGaussUsername() {
        return properties.getProperty("gauss.username");
    }

    public String getGaussPassword() {
        return properties.getProperty("gauss.password");
    }

    public int getCheckpointInterval() {
        return Integer.parseInt(properties.getProperty("flink.checkpoint.interval"));
    }

    public int getBatchSize() {
        return Integer.parseInt(properties.getProperty("flink.batch.size"));
    }

    public int getBatchInterval() {
        return Integer.parseInt(properties.getProperty("flink.batch.interval"));
    }

    public int getMaxRetries() {
        return Integer.parseInt(properties.getProperty("flink.max.retries"));
    }
} 